import axios from 'axios'
import { objectToFormData } from 'object-to-formdata'

export const getUploadToken = async () => {
  return axios.get(process.env.VUE_APP_API_BASE_URL + '/qiniu/uploadtoken/chatroom')
}

export const postImage = async (image, token, url) => {
  var config = {
    method: 'POST',
    url: url,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
    data: objectToFormData({
      key: 'chatroom_cache_' + new Date().valueOf(),
      token: token,
      file: image,
    }),
  }
  return axios(config)
}

export const getMusic = async () => {
  return axios.get(process.env.VUE_APP_API_BASE_URL + '/musics/')
}

export const postNotes = async (notes) => {
  return axios.post(process.env.VUE_APP_API_BASE_URL + '/notes/', notes)
}

export const getNotes = async () => {
  return axios.get(process.env.VUE_APP_API_BASE_URL + '/notes/')
}
